﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using CrossSiteCollectionSearchConfigurator;

namespace EngineTesterHarness
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("usage: EngineTesterHarness.exe SiteCollectionUrl");
                Console.WriteLine("         e.g. EngineTesterHarness.exe http://localhost/");
                return;
            }
            SPSite testSite = new SPSite(args[0]);
            try
            {
                SearchSettingsPropogatorEngine.RunEngine(testSite.WebApplication);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error running job engine, details follow");
                Console.Error.WriteLine("Exception: "+ ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
                if (null != ex.InnerException)
                {
                    Exception inner = ex.InnerException;
                    while (null != inner)
                    {
                        Console.Error.WriteLine("InnerException: " + inner.Message);
                        Console.Error.WriteLine(inner.StackTrace);
                        inner = inner.InnerException;
                    }
                }
            }
            finally
            {
                //Allways dispose!
                testSite.Dispose();
            }
        }
    }
}
